//
//  DigitalViewController.m
//  GJDigitalDemo
//
//  Created by wbb on 2021/11/9.
//

#import "DigitalViewController.h"
#import <GJDigitalSDK/GJDigitalSDK.h>

@interface DigitalViewController ()<DigitalViewDelegate>

@end

@implementation DigitalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    
    /// 初始化数据
//    DigitalConfig *config = [DigitalConfig shareConfig];
//    config.serverIP = @"new.guiji.ai";
//    config.servePort = 5222;
//    config.robotCode = @"230738573542952960";
//    config.robotMode = @"bot";
//    config.stunList = @[@"stun:47.114.110.197:23478"];
//    config.domain = @"guiji.ai";
//    config.resource = @"dhrtc";
//    config.userJID = @"iray-proxy@guiji.ai";
//    config.isShowLocalVideo = YES;
//    config.isShowLocalAudio = YES;
//    config.usingFrontCamera = YES;
//    config.openAsr = @"true";
    
    
    
    
    /// 初始化view
    DigitalView *digitalView = [[DigitalView alloc] initWithFrame:self.view.bounds];
    digitalView.delegate = self;
    [self.view addSubview:digitalView];
    
}
/// 错误信息返回
/// @param error error
- (void)onError:(NSError *)error {
    [self addAlert:error.localizedDescription];

}
/// 会话建立成功
- (void)onChatCreate {
    
}

/// 中控获取到渲染端信息后通知客户端
/// @param ID id
/// @param name name
- (void)onRender:(NSString *)ID name:(NSString *)name {
    
}

/// 中控获取到播放话术后将字幕以及话术指令推送给客户端
/// @param dic 字幕以及话术指令
- (void)onCommand:(NSDictionary *)dic {
    NSLog(@"onCommand ======= %@", dic);
}

/// 当前中端回调的事件
/// @param msg 事件名字
- (void)onCustomMsg:(NSString *)msg {
    NSLog(@"onCustomMsg ==== %@", msg);
}

/// webrtc连接状态回调
/// @param state RTCIceConnectionState
- (void)didIceConnectionChange:(RTCIceConnectionState)state {
    NSLog(@"didIceConnectionChange ==== %ld", (long)state);

}

/// 中控获取不到渲染端信息后通知客户端繁忙
- (void)onBusy {
    [self addAlert:@"机器人资源繁忙，请稍候再试!"];
}

/// 中控结束通话，发送bye事件
- (void)onByeBye {
    [self addAlert:@"中控结束通话，发送bye事件"];

}
- (void)addAlert:(NSString *)content  {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:content preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
            //响应事件
            NSLog(@"action = %@", action);
        }];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
    });
    
}


@end
